package game.engine.base

import game.engine.base.pool.MatrixPool
import kotlin.math.max
import kotlin.math.min

object CoreUtil {

    // matrix.invert 不会改变自身
    val matrixPool = MatrixPool()

    // matrix数组横着存的
    val tmpMatrixArray = floatArrayOf(0f,0f,0f,0f,0f,0f,0f,0f,0f)

    val DEG_TO_RAD : Float = (Math.PI / 180f).toFloat()
    val RAD_TO_DEG : Float =  (180 / Math.PI).toFloat()

    fun toRad(degress:Float):Float = DEG_TO_RAD * degress
    fun toDegress(rad:Float):Float = RAD_TO_DEG * rad

    // 返回 [min,max]
    fun randomFloat(min:Float,max:Float):Float = (Math.random().toFloat() * (max - min + 1f)) + min

    // 返回  [min,max]
    fun randomInt(min:Int,max:Int):Int = (Math.random() * (max - min + 1)).toInt() + min

    // 将  value 限制在 [left,right]  范围
    fun clampInt(value:Int,left:Int,right:Int) : Int = min(max(left,value),right)

    // 将  value 限制在 [0f,1f]  范围
    fun clamp01(value:Float):Float = min(max(0f,value),1f)
}

